<template>
  <div class="empty-dialog">
    <base-dialog
      :title="dialogType == 'create' ? '新增{{tableComment}}' : '编辑{{tableComment}}'"
      :modal="dialogVisible"
      width="50px"
      @before-close="close"
      v-if="dialogVisible"
    >
      <!-- form表单开始 -->
      <el-form :model="createForm" :rules="rules" ref="createForm" label-width="auto" size="mini">
        <el-row>{{each tableColumns}}
          <el-col :span="24">
            <el-form-item label="{{$value.columnComment}}" prop="{{$value.columnName}}">
              <el-input v-model="createForm.{{$value.columnName}}" clearable placeholder="请输入" :maxlength="{{$value.columnLength}}"></el-input>
            </el-form-item>
          </el-col>{{/each}}
        </el-row>
      </el-form>
      <!-- form表单结束 -->
      <div slot="footer" class="dialog-footer flex flex-x-end">
        <el-button size="mini" @click="close">取消</el-button>
        <el-button size="mini" type="primary" @click="save">确定</el-button>
      </div>
    </base-dialog>
  </div>
</template>

<script>
import pageDialog from '@/mixins/basic-dialog'
import mixin from '@/plugin/mixins/mixin'
import { apiMethods, createForm, createFormRules } from '../config'

export default {
  mixins: [pageDialog, mixin],
  data() {
    return {
      rules: createFormRules.call(this),
      apiMethods: apiMethods.call(this),
      // 页面数据
    }
  },
  methods: {
    async initOpen(row) {
      if (!row) {
        this.createForm = { ...createForm.call(this) }
        return
      } else {
        this.createForm = { ...row }
      }
    },
    async save() {
      // 可以提前处理提交参数
      this.dialogSubmit(this.createForm)
    }
  }
}
</script>
